package com.atguigu.gmall.realtime.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author lizhenchao@atguigu.cn
 * @Date 2021/3/20 10:39
 */
public class MyTimeUtil {
    public static Long toTs(String dateTime, String... format) {
        try {
            String f = "yyyy-MM-dd HH:mm:ss";
            if (format.length == 1) {
                f = format[0];
            }
            return new SimpleDateFormat(f).parse(dateTime).getTime();
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    public static String toDateTimeString(Long dateTime, String... format) {
        try {
            String f = "yyyy-MM-dd HH:mm:ss";
            if (format.length == 1) {
                f = format[0];
            }
            return new SimpleDateFormat(f).format(new Date(dateTime));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
